part of '../repository.dart';

const _kPronunciationSettingsDataDialectKey = 'dialect';
const _kPronunciationSettingsDataSpeechRateKey = 'speech_rate';
const _kPronunciationSettingsDataAmVoiceKey = 'am_voice';
const _kPronunciationSettingsDataBrVoiceKey = 'br_voice';

class _PronunciationSettingsDataDto extends Equatable {
  const _PronunciationSettingsDataDto._internal({
    required this.dialectDto,
    required this.speechRate,
    required this.amVoice,
    required this.brVoice,
  });

  final _DialectDto dialectDto;
  final double speechRate;
  final String? amVoice;
  final String? brVoice;

  @override
  List<Object?> get props {
    return [
      dialectDto,
      speechRate,
      amVoice,
      brVoice,
    ];
  }

  factory _PronunciationSettingsDataDto.fromJson(Map<String, dynamic> json) {
    final dialectDto = _DialectDto.fromString(json[_kPronunciationSettingsDataDialectKey]);

    return _PronunciationSettingsDataDto._internal(
      dialectDto: dialectDto,
      speechRate: json[_kPronunciationSettingsDataSpeechRateKey],
      amVoice: json[_kPronunciationSettingsDataAmVoiceKey],
      brVoice: json[_kPronunciationSettingsDataBrVoiceKey],
    );
  }

  factory _PronunciationSettingsDataDto.fromEntity(
      PronunciationSettingsData pronunciationSettingsData) {
    final dialectDto = _DialectDto.fromEntity(pronunciationSettingsData.dialect);

    return _PronunciationSettingsDataDto._internal(
      dialectDto: dialectDto,
      speechRate: pronunciationSettingsData.speechRate,
      amVoice: pronunciationSettingsData.amVoiceTitle,
      brVoice: pronunciationSettingsData.brVoiceTitle,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      _kPronunciationSettingsDataDialectKey: dialectDto.toString(),
      _kPronunciationSettingsDataSpeechRateKey: speechRate,
      _kPronunciationSettingsDataAmVoiceKey: amVoice,
      _kPronunciationSettingsDataBrVoiceKey: brVoice,
    };
  }

  PronunciationSettingsData toEntity() {
    return PronunciationSettingsData(
      dialect: dialectDto.toEntity(),
      speechRate: speechRate,
      amVoiceTitle: amVoice,
      brVoiceTitle: brVoice,
    );
  }
}
